/*
 * CAN_Module.h
 *
 *  Created on: Sep 2, 2021
 *      Author: ZhangJianCe
 */

#ifndef CAN_MODULE_H_
#define CAN_MODULE_H_


#include "Config.h"
#include "can.h"


#ifndef Model_NO_CAN_Struct_Define
typedef struct {
  uint32_t ID;
  uint8_t Length;
  uint8_t Extended;
  uint8_t Remote;
  uint8_t Data[8];
  uint8_t Fram_Count;
} myCAN;

typedef struct {
  uint32_t ID;
  uint8_t Length;
  uint8_t Extended;
  uint8_t Remote;
  uint8_t Data[8];
  uint8_t Ena;
  /*Ena Status Value Table
   * bit1:Send enable
   * bit0:send status
   *
   * 0b00: No Sent request
   *
   * 0b01: Currently Sent request，Successfully executed, and the status flasg need clear,
   *
   * 0b10：Currently Sent request,Need to be executed, and the action is not completed
   *
   * 0b11: Currently Sent request,and the action has been completed
   * */
} CANOut;
#endif

/*Custom accept CAN receive frame*/
typedef myCAN CAN_RX_Frame;

/*CAN MESSAGE comes from the can message.h that comes with matlab*/
typedef CANOut CAN_TX_Frame;


#ifdef CAN0_ON
	#ifdef CAN0_MB0_RX_ON
		#ifdef CAN0_MB0_Address
			#define CAN0_MB0_Buff (*(CAN_RX_Frame *)CAN0_MB0_Address)
		#else
			extern CAN_RX_Frame CAN0_MB0_Buff;
		#endif
	#endif
	#ifdef CAN0_MB0_TX_ON
		#ifdef CAN0_MB0_Address
			#define CAN0_MB0_Buff (*(CAN_TX_Frame *)CAN0_MB0_Address)
		#else
			extern CAN_TX_Frame CAN0_MB0_Buff;
		#endif
	#endif
	#ifdef CAN0_MB1_RX_ON
		#ifdef CAN0_MB1_Address
			#define CAN0_MB1_Buff (*(CAN_RX_Frame *)CAN0_MB1_Address)
		#else
			extern CAN_RX_Frame CAN0_MB1_Buff;
		#endif
	#endif
#endif

void CAN_Transmit(CAN_HandleTypeDef *hcan,CAN_TX_Frame *Frame_Info);


#endif
